<template>
	<view class="container">
		<view class="box-form">
			<u--form
			labelPosition="left"
			:model="data"
			:rules="rules"
			ref="uForm">
				<u-form-item
					labelWidth="100"
					label="名称:"
					prop="name">
					<u--input v-model="data.name" placeholder="分类名称"></u--input>
				</u-form-item>
				<u-form-item
					labelWidth="100"
					label="别名:"
					prop="alias">
					<u--input v-model="data.alias" placeholder="分类别名"></u--input>
				</u-form-item>
			</u--form>
			<u-button class="box-sign-in" @click="submit" color="#c00000" loadingMode="semicircle" :loading="loading" loadingText="保存中..." loadingSize="60">保 存</u-button>
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	import { articleAddcates } from '@/api/getList.js';
	export default {
		data() {
			return {
				loading: false,
				data: {
					name: "",// 文章分类
					alias: ""// 文章分类别名
				},
				rules: {
					'name': {
						type: 'string',
						required: true,
						message: '请输入文章分类名称',
						trigger: ['blur']
					},
					'alias': {
						type: 'string',
						required: true,
						message: '请输入文章分类别名',
						trigger: ['blur']
					}
				}
			}
		},
		created() {

		},
		methods: {
			// 保存
			submit(){
				this.$refs.uForm.validate().then(async res => {
					this.loading = true;
					const data = await articleAddcates(this.data);
					this.$refs.uToast.show({ message: data.message });
					this.loading = false;
					this.$refs.uForm.resetFields();
				}).catch(errors => {
					this.loading = false;
				});
			}
		},
		onReady() {
			//如果需要兼容微信小程序，并且校验规则中含有方法等，只能通过setRules方法设置规则。
			this.$refs.uForm.setRules(this.rules)
		},
	}
</script>

<style lang="scss" scoped>
	page {
		box-sizing: border-box;
		background-color: #FFFFFF;
	}
	.container {
		width: 100%;
		box-sizing: border-box;
		padding: 0 40rpx;
		min-height: calc(100vh);
		background-color: #FFFFFF;
	}
	.box-form {
		padding-top: 20rpx;
	}
	.box-sign-in {
		height: 70rpx;
		margin-top: 20rpx;
	}
</style>
